package ${table.controllerClassPackage};

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import ${table.serviceClassPackage}.${table.beanName}Service;
<#if table.isGeneratorSelect>
import ${table.reClassPackage}.R;
import org.springframework.web.bind.annotation.PostMapping;
</#if>
<#if table.isGeneratorSelect>
import ${table.entityClassPackage}.${table.beanName};
</#if>
<#if table.isGeneratorDelete>
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.GetMapping;
</#if>
<#if table.isGeneratorExcelImport>
import ${table.excelImportClassPackage}.${table.beanName}Listener;
import org.springframework.web.multipart.MultipartFile;
import com.alibaba.excel.EasyExcel;
</#if>
<#if table.isGeneratorExcelDown>
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.alibaba.excel.EasyExcel;
import java.util.List;
import java.io.File;
</#if>
/**
* @author：${table.author}
* @since：${table.date}
* @remark：${table.comment}
*/
@Controller
@RequestMapping("/${table.somallbeanName}")
@ResponseBody
public class ${table.beanName}Controller {
     @Autowired
     private ${table.beanName}Service ${table.somallbeanName}ServiceImpl;

     <#if table.isGeneratorSelect>
     @PostMapping("/${table.somallbeanName}ListByPage<#if table.selectCustomWay?has_content>${table.selectCustomWay}</#if>")
     public R listByPage<#if table.selectCustomWay?has_content>${table.selectCustomWay}</#if>(@RequestBody ${table.beanName}  ${table.somallbeanName}) {
        return R.ok(${table.somallbeanName}ServiceImpl.listByPage<#if table.selectCustomWay?has_content>${table.selectCustomWay}</#if>(${table.somallbeanName}));
     }
     </#if>

     <#if table.isGeneratorSave>
     @PostMapping("/${table.somallbeanName}Save")
     public R save(@RequestBody ${table.beanName} ${table.somallbeanName}) {
          return R.ok(${table.somallbeanName}ServiceImpl.save(${table.somallbeanName}));
     }
     </#if>

     <#if table.isGeneratorUpdate>
     @PostMapping("/${table.somallbeanName}UpdateById")
     public R updateById(@RequestBody ${table.beanName} ${table.somallbeanName}) {
          return R.ok(${table.somallbeanName}ServiceImpl.updateById(${table.somallbeanName}));
     }
     </#if>

     <#if table.isGeneratorDelete>
     @GetMapping("/${table.somallbeanName}DeleteById/{id}")
     public R deleteById(@PathVariable String id) {
          return R.ok(${table.somallbeanName}ServiceImpl.deleteById(id));
     }
     </#if>
     <#if table.isGeneratorExcelImport>
     @PostMapping("/${table.somallbeanName}ExcelImport")
     public R excelImport(MultipartFile file) throws Exception {
          EasyExcel.read(file.getInputStream(), ${table.beanName}.class, new ${table.beanName}Listener(${table.somallbeanName}ServiceImpl)).sheet().doRead();
          return R.ok("导入成功");
     }
     </#if>
    <#if table.isGeneratorExcelDown>
    @PostMapping("/${table.somallbeanName}ExcelDown")
    public R excelDown(@RequestBody ${table.beanName} ${table.somallbeanName}) throws Exception {
        QueryWrapper<${table.beanName}> wrapper = new QueryWrapper<>();
          <#if table.selectCustomConditionExcelList?size != 0>
              <#list table.selectCustomConditionExcelList as custom>
        <#assign firstChar = custom.columnBean?substring(0, 1)>
        <#assign remainingChars = custom.columnBean?substring(1)>
        if(${table.somallbeanName}.get${firstChar?capitalize}${remainingChars}() != null &&!"".equals(${table.somallbeanName}.get${firstChar?capitalize}${remainingChars}())){
        wrapper.${custom.condition}("${custom.column}",${table.somallbeanName}.get${firstChar?capitalize}${remainingChars}());
        }
            </#list>
        </#if>
          List<${table.beanName}> ${table.somallbeanName}List=${table.somallbeanName}ServiceImpl.list(wrapper);
        File fileName = new File(System.currentTimeMillis() + ".xlsx");
        EasyExcel.write(fileName, ${table.beanName}.class).sheet("模板").doWrite(${table.somallbeanName}List);
        return R.ok("导入成功");
    }
    </#if>

}

